<?php
class Test extends CI_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->database();
        
    }

           /***
            
             $.ajax({
                type: "POST",
                url: "<?php echo base_url().'projects/ajax_assign_personnels_process/'; ?>",
                data: form_data,
                success: function(response)
                {
                   alert(response);
                }
             }); 
       
            * **/
	function index($offset = 0)
	{
            $this->load->model('personnel_model');
			
			$this->db->query("UPDATE tblpersonnels set skill='Kĩ năng' WHERE id='100'");
			echo $this->db->affected_rows();
			
			//$pns = array('1','3','7');
			///$p = join(',', $pns);
			//$arr = $this->db->query("SELECT * FROM tblpersonnels WHERE id IN ($p) ")->result_array();
			//echo arrTotable($arr,true);
			
			
			//$this->personnel_model->get_personnels_yes_no_of_boss(16,295);
			//$a = $this->personnel_model->get_for_assign_free(15,'-1');
			
            //$a = $this->work_model->get_child_works_of_pn('15','3');
            //print_r($a);
             //if(is_pm('1')) echo 'haha';
            //$this->load->model('personnel_model');
            //print_r($this->personnel_model->get_personnels_of_parentmanager('12','287'));
            //echo $this->personnel_model->is_busy('12','9','243');
            //echo "<meta http-equiv='Content-Type' content='text/html;charset=utf-8' />";
            //echo ($this->personnel_model->get_work_busy_string('12','3','40-2',null));
//             echo works_multi_level_form($this->work_model->get_works(1));
//            $arr0 = array(array('id'=>1,'name'=>'n1','i'=>11),array('id'=>2,'name'=>'n2','i'=>12));
//            $arr1 = array(array('id'=>1,'name'=>'n1'),array('id'=>2,'name'=>'n2'));
//            $arr2 = array();
//            $arr3=(array_merge($arr0,$arr1));
//            print_r(array_merge($arr2,$arr3));            //$this->load->helper('cookie');
            //if(1){
//            $this->load->library('encrypt');
//            echo $this->encrypt->decode($_COOKIE['pmlg']);
            //}
//                $newdata = array(
//                   'username'  => 'johndoe',
//                   'email'     => 'johndoe@some-site.com',
//                   'logged_in' => TRUE
//               );
//
//                $this->session->set_userdata($newdata);
//                $arr = $this->session->all_userdata();
//                print_r($arr);
//                print_r($arr['username']);
//                $this->session->set_userdata('username','trandinhtrong');
//                print_r($this->session->all_userdata());
//                //$this->session->unset_userdata('username');
//                $this->session->unset_userdata(array('username'=>'','email'=>''));
//                $arr = $this->session->all_userdata();
//                print_r($this->session->all_userdata());
//                if(isset($arr['username'])) echo "<br/> co";
//                else echo "<br/> ko co";
//                echo $this->session->userdata['username'];
                //
               //$this->load->model('personnel_model');
               //echo arrTotable($this->personnel_model->get_of_manager_busy('1','44'),true);
//             $pj_id = '1';
//             $workid = '3';
//             $pn_id  = '1';
//             $this->load->model('work_model');
//             $arr = $this->work_model->get_works_and_time_of_project_pn($pj_id,$pn_id);
//             if(count($arr)>0){
//                 require_once (APPPATH.'jpgraph/jpgraph.php');
//                 require_once (APPPATH.'jpgraph/jpgraph_gantt.php');
//                 $data = array();
//                 for($i=0;$i<count($arr);$i++){
//                     if($arr[$i]['workid']!='0'){
//                         $data[] = array($i,ACTYPE_NORMAL,'CV '.$arr[$i]['workname'],$arr[$i]['beginonreality'],$arr[$i]['enddaywork'],'');
//                     }else {
//                          $data[] = array($i,ACTYPE_NORMAL,'Du an '.$arr[$i]['projectname'],$arr[$i]['begindate'],$arr[$i]['enddate'],'');
//                     }
//                 }
//                 $constrains = array();
//                 $progress = array();
//                 $graph = new GanttGraph();
//                 $graph->title->Set("Cộng việc hiện tại của ".$arr[0]['personnelname']);
//                 // Setup scale
//                 $graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH | GANTT_HDAY | GANTT_HWEEK);
//                 $graph->scale->week->SetStyle(WEEKSTYLE_FIRSTDAYWNBR);
//                 // Add the specified activities
//                 $graph->CreateSimple($data,$constrains,$progress);
//                 // .. and stroke the graph
//                $graph->Stroke();
//                 //echo arrTotable($arr,true);
             
            
            
//            $this->load->model('project_model');
//           $arr = $this->project_model->get_resources_materials_of_pn_project('1','1');
//           print_r ($arr);

//         $this->db->insert('test',array('text'=>'aaa'));
//         echo $this->db->insert_id();
//            $this->load->model('personnel_model');
//            $arr =  ($this->personnel_model->get_for_assign_busy('1'));
//            $arr2 =  ($this->personnel_model->get_for_assign_free('1'));
            //echo arrTotable($arr,true);
         //   echo  arrTooptions(
           //             $this->personnel_model->get_for_assign_free('1'),'name','id');
//            $time1 = "23:00";
//            $time2 = "09:00";
//            if (strtotime($time1) > strtotime($time2)) {
//               echo "haha";
//            }else echo "hehe";
//		ob_start();
//		$this->ajax_page( 0 );
//		$initial_content = ob_get_contents();
//		ob_end_clean();	
//
//		$data['table'] = "<div id='content'>" . $initial_content . "</div>" ;
//
//	    $this->load->view('page',$data);

	}

	function ajax_page($offset = 0)
	{
            $this->load->model('model_table');
            $this->load->library('Jquery_pagination');

            $config['base_url'] = site_url('test/ajax_page/');
            /* Here i am indicating to the url from where the pagination links and the table section will be fetched */

            $config['div'] = '#content';
            /* CSS selector  for the AJAX content */

            $limit = 20;
            $config['total_rows'] = $this->model_table->num_rows();
	    $config['per_page'] = $limit;

	    $this->jquery_pagination->initialize($config);

	    $this->load->library('table');

	    $html =  $this->jquery_pagination->create_links() . '<br />'
				.  $this->table->generate($this->model_table->content( $limit, $offset));

		echo $html;
	}
        
        function testarray(){
            $arr = array(array('id'=>1,'name'=>'name'),array('id'=>2,'name'=>'name'),array('id'=>3,'name'=>'name'),array('id'=>2,'name'=>'name'),array('id'=>2,'name'=>'name'));
            echo arrTotable($arr,true);
            for($i=0;$i<count($arr);$i++){
                for($j=$i+1;$j<count($arr);$j++){
                        if($arr[$j]['id']!='0'&&$arr[$i]['id']==$arr[$j]['id']){
                            $arr[$i]['name'].= '----'.$arr[$j]['name'];
                            $arr[$j]['id'] = '0';
                            //unset($arr[$j]); //echo "===========$i-----$j";
                        }                 
                }
            }
            echo arrTotable($arr);   
        }
}

?>